/*
 *所有关于MaterialRequisition类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*MaterialRequisitionService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using VOL.Core.BaseProvider;
using VOL.Core.Extensions.AutofacManager;
using VOL.Entity.DomainModels;
using System.Linq;
using VOL.Core.Utilities;
using System.Linq.Expressions;
using VOL.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using MyMES.IRepositories;
using MyMes.Infrastructure;
using MyMES.Dto;
using MyMES.Infrastructure;
using MyMES.Repositories;

namespace MyMES.Services
{
    public partial class MaterialRequisitionService
    {
        private readonly IBaseRepository<MaterialRequisition> _materialRequisitionRepository;

        public MaterialRequisitionService(IBaseRepository<MaterialRequisition> materialRequisitionRepository)
        {
            _materialRequisitionRepository = materialRequisitionRepository;
        }


        /// <summary>
        /// 获取生产领料信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<APIPage<MaterialRequisition>> GetMaterialRequisitionList(GetMaterialRequisitionListDTO param)
        {
            var list = _materialRequisitionRepository.GetAll();

            var supplierpaging = new APIPage<MaterialRequisition>()
            {
                Data = list.Skip((param.PageIndex - 1) * param.PageSize).Take(param.PageSize).ToList(),
                TotalCount = list.Count(),
                TotalPage = (int)Math.Ceiling(list.Count() * 1.0 / param.PageSize)
            };

            return supplierpaging;
        }

        /// <summary>
        /// 新增生产领料
        /// </summary>
        /// <param name="Salesreturns"></param>
        /// <returns></returns>
        public async Task<int> CreateMaterialRequisition(MaterialRequisition materialRequisition)
        {
            var result = await _materialRequisitionRepository.AddAsync(materialRequisition);

            return result;
        }

        /// <summary>
        /// 删除生产领料信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<int> DeleteMaterialRequisition(MaterialRequisition salesreturns)
        {
            var result = await _materialRequisitionRepository.Remove(salesreturns);

            return result;
        }

        /// <summary>
        /// 修改生产领料信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<int> UpdateMaterialRequisition(MaterialRequisition salesreturns)
        {
            var result = await _materialRequisitionRepository.UpdateAsync(salesreturns);

            return result;
        }
    }
}
